import java.util.ArrayList;
import java.util.Random;

public class Cards {
    private static final String[] suits = {"♥", "♣", "♦", "♠"};

    //生成一副牌  4个花色     13张牌
    public ArrayList<Card> buyCards(ArrayList<Card> arrayList) {
        for (int j = 0; j < 4; j++) {
            //四个花色
            for (int i = 1; i <= 13; i++) {
                //13张不同的面值
                Card card = new Card(i, suits[j]);
                arrayList.add(card);
            }
        }
        return arrayList;
    }

    //洗牌
    public void shuffle(ArrayList<Card> arrayList) {
        Random random = new Random();
        for (int i = 0; i < 52; i++) {
            int rand = random.nextInt(52); // 0-51随机数
            //进行交换
            swap(arrayList, i, rand);
        }
    }

    //交换
    private void swap(ArrayList<Card> arrayList, int a, int b) {
        Card tmp = arrayList.get(a);
        arrayList.set(a, arrayList.get(b));
        arrayList.set(b, tmp);
    }

    //三个人，每个人轮流抓一张牌,轮流5次
    public ArrayList<ArrayList<Card>> drawCard(ArrayList<Card> arrayList) {
        ArrayList<Card> arrayList1 = new ArrayList<>();
        ArrayList<Card> arrayList2 = new ArrayList<>();
        ArrayList<Card> arrayList3 = new ArrayList<>();

        ArrayList<ArrayList<Card>> personList = new ArrayList<>();
        personList.add(arrayList1);
        personList.add(arrayList2);
        personList.add(arrayList3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //先拿到最上面的一张牌
                Card upCard = arrayList.get(0);
                //挨个放入各自的ArrayList当中
                personList.get(j).add(upCard);
                //拿走一张，删除最上面的一张
                arrayList.remove(0);
            }
        }
        return personList;
    }
}
